<style>
    .layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {height:34px;line-height:34px;padding:0 8px;}
</style>
<body>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
			<input type="hidden" name="r_id" value="{{.role_user.Id}}">
            <table id="role-menu-table" class="layui-table" lay-filter="role-menu-table"></table>
        
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
				</div>
			</div>
		</div>
    </div>
</div>

<script>
	//树形表格渲染参数
	var tree_table_render_params = {}
    layui.use(['table', 'treetable','miniPage'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var treetable = layui.treetable;
		var miniPage = layui.miniPage;
		var role_id = "{{.role_user.Id}}"
		var reqUrl = '/admin/rbac/menu?role_id='+role_id;
		var form = layui.form;
		
        // 表格参数设置
		tree_role_menu_table_render_params = {
			treeColIndex: 1,
			treeSpid: -1,
			treeIdName: 'id',
			treePidName: 'ParentId',
			elem: '#role-menu-table',
			url: reqUrl,
			page: false,
			method:'post', //这里可以写post请求,默认get	
			checkboxHtml:true, //是否显示 checkbox 框
			cols: [[
				{type: 'numbers'},
				{field: 'AuthorityName', minWidth: 200, title: '权限名称'},
				{field: 'Authority', title: '权限标识'},
				{field: 'MenuUrl', title: '菜单url'},
				{field: 'Status', width: 80, align: 'center', title: '状态',templet: function (d) {return d.Status ==0 ? '显示':"隐藏";}},
				{field: 'OrderNumber', width: 80, align: 'center', title: '排序号'},
				{
					field: 'IsMenu', width: 80, align: 'center', templet: function (d) {
						if (d.IsMenu == 1) {
							return '<span class="layui-badge layui-bg-gray">按钮</span>';
						}
						if (d.ParentId == -1) {
							return '<span class="layui-badge layui-bg-blue">目录</span>';
						} else {
							return '<span class="layui-badge-rim">菜单</span>';
						}
					}, title: '类型'
				},
				
			]],
			done: function () {
				layer.closeAll('loading');
			}
		}
        
		// 渲染表格
		treetable.render(tree_role_menu_table_render_params);
		
		 //监听提交
        form.on('submit(saveBtn)', function (data) {
			//获取选中id
			var ids = $(".checkbox-menu").map(function(){ 
				if($(this).is(':checked')) {
					return this.value
				}
			}).get().join(','); 
			//console.log(name); return false;
					
			var url = "/admin/rbac/roleMenu"
			
            $.post(url,{ids:ids,r_id:role_id},function(resp){
				//console.log(resp)
				if(resp.code == 0){
					//修改成功
					layer.msg("提交成功",{end:function(){
						table.reload('roleCurrentTableId')
						parent.layer.closeAll();
					}});
					
				}else{
					layer.msg(resp.msg);
				}
		    },"json");
            return false;
        });
       
    });
	
</script>
</body>
</html>